package com.atde._05_behavioral_design_patterns.memento;


/**
 * @BelongsProject: hsp_java_design_mode
 * @BelongsPackage: com.atde._05_behavioral_design_patterns.memento
 * @Author: Del
 * @CreateTime: 2025-06-30  02:25
 * @Description: 备忘录模式 --- 客户端
 * @Version: 1.0
 */
public class Client {
    public static void main(String[] args) {
        // 创建原始对象
        Originator originator = new Originator();

        // 创建备忘录管理器
        Caretaker caretaker = new Caretaker();

        // 保存了状态1
        originator.setState("状态01：100");
        caretaker.add(originator.saveStateMemento());
        System.out.println("当前状态：" + originator.getState());

        // 改变原始对象的状态
        originator.setState("状态02：200");
        caretaker.add(originator.saveStateMemento());
        System.out.println("当前状态：" + originator.getState());

        originator.setState("状态03：300");
        caretaker.add(originator.saveStateMemento());
        System.out.println("当前状态：" + originator.getState());

        // 回复到 200 状态
        originator.getStateFromMemento(caretaker.get(1));
        System.out.println("当前状态：" + originator.getState());
    }
}
